package com.yangxk.kadmin.web.module.system.controller;

import com.yangxk.kadmin.web.module.system.form.DictEditForm;
import com.yangxk.kadmin.web.module.system.form.DictQueryForm;
import com.yangxk.kadmin.web.module.system.service.DictService;
import com.yangxk.kadmin.web.module.system.po.Dict;
import com.yangxk.kadmin.common.beans.Result;
import com.yangxk.kadmin.web.common.annotation.Permission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
public class DictController {
    @Autowired
    private DictService dictService;

    @GetMapping("/dict/list")
    public Result queryByPage(@RequestParam(required = false, defaultValue = "0") Long parentId) {
        return Result.ofSuccess(dictService.queryList(parentId));
    }

    @PostMapping("/dict/add")
    @Permission("dict:add")
    public Result add(@RequestBody DictEditForm form) {
        dictService.addDict(form);
        return Result.ofSuccess();
    }

    @GetMapping("/dict/detail")
    public Result<Dict> queryById(long id) {
        Dict dict = dictService.selectByPrimaryKey(id);
        return Result.ofSuccess(dict);
    }

    @PostMapping("/dict/update")
    @Permission("dict:update")
    public Result update(@RequestBody DictEditForm form) {
        dictService.updateDict(form);
        return Result.ofSuccess();
    }

    @GetMapping("/dict/delete")
    @Permission("dict:delete")
    public Result delete(long id) {
        dictService.deleteDict(id);
        return Result.ofSuccess();
    }

    @GetMapping("/dict/all")
    public Result all() {
        return Result.ofSuccess(dictService.getAll());
    }

}
